const Koa=require('koa');
const app=new Koa();
const axios = require('axios');
const instance = axios.create({});

app.use(async(ctx,next)=>{
    const start = new Date();
    await next();  // 下一棒
    const delta = new Date()-start;
    console.log(`请求耗时${delta}MS`);
    console.log(ctx.state.baiduHTML);
})

app.use(async(ctx,next)=>{
    ctx.state.baiduHTML=await instance.get('https://www.baidu.com');
    next();

})

// 挂载一个中间件 req -> res
app.use((ctx,next)=>{
    console.log('任何一个用户来，中间件函数都会得到执行');
    next();
})


// app.use((ctx,next)=>{
//     console.log('1111');
// })

// app.get('/') express

app.listen(8000,()=>{
    console.log('服务启动');
})